/*
*调用到达和二条程序并记录信息
*@fuyuwen.masa
*/
reach_second();
function reach_second()
{
	if(getCookie('Reach_Media_Flag') == 1 || getCookie('CLICK_STEPS_SECOND') ==1)
	{
		jQuery.get("/reach_second.php",{time:Math.random()}, function(data) {
				//同步联盟到达与二跳的Cookie
				var shareKeyUrl = 'http://'+document.domain+'/api/sharekey.php?t='+Math.random();
				jQuery.get(shareKeyUrl, function(keydata) {
					//原来返回的是 var union_val='xxxx'; ，在这里只取中间的值xxxx
					var pos = keydata.indexOf("'");
					if (pos <= 0) return;					
					keydata = keydata.substring(pos + 1);					
					pos = keydata.lastIndexOf("'");
					if (pos <= 0) return;					
					keydata = keydata.substring(0, pos);		
					if(keydata && keydata != undefined && keydata != ''){
						var client = getClientUrl();
						for(var i=0;i < client.length;i++){
							jQuery.getScript(client[i]+'&union_cookie_value='+encodeURIComponent(keydata));
						}
					}					
				});
		});
	}else{
		return false;
	}
}
/*
*请注意这里是男装程序调用女装地址
*/
function  getClientUrl() {
	var current_host = document.domain;
    var rand = Math.random();
    if(current_host.match('test.')){
    	return new Array('http://test.vivian.cn/syncUnionCookie.php?T='+rand);
    }else if (current_host.match('www2.')){
    	return new Array('http://www2.vivian.cn/syncUnionCookie.php?T='+rand);
    }else if (current_host.match('www.')){
    	return new Array('http://www.vivian.cn/syncUnionCookie.php?T='+rand);
    }
}



function getCookie(name) 
{
    var bikky = document.cookie;
    name += "=";
    var i = 0; 
    while (i < bikky.length) 
    {
      var offset = i + name.length;
      if (bikky.substring(i, offset) == name) 
      { 
        var endstr = bikky.indexOf(";", offset); 
        if (endstr == -1) endstr = bikky.length;
          return unescape(bikky.substring(offset, endstr)); 
      }
        i = bikky.indexOf(" ", i) + 1; 
        if (i == 0) break; 
    }
    return null; 
}